package com.kyd.push.push;

import com.kyd.push.common.enums.ValueEnum;
import com.kyd.push.common.utils.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * PushRequest 推送消息请求对象
 *
 * @author kejw on 2018/9/26
 */
public class PushRequest {

	/**
	 * 通知内容体。是被推送到客户端的内容。与 message 一起二者必须有其一，可以二者并存
	 */
	private String notification;

	/**
	 * 通知扩展
	 */
	private Map<String, String> extras = new HashMap<>();

	/**
	 * 消息内容体。是被推送到客户端的内容。与 notification 一起二者必须有其一，可以二者并存
	 */
	private String message;

	public static PushRequest newInstance() {
		return new PushRequest();
	}

	public PushRequest setNotification(String notification) {
		this.notification = notification;
		return this;
	}

	public String getNotification() {
		return notification;
	}

	/**
	 * 添加通知扩展
	 *
	 * @param key
	 * @param value
	 * @return
	 */
	public PushRequest addExtra(String key, String value) {
		this.extras.put(key, value);
		return this;
	}

	/**
	 * 添加通知扩展
	 *
	 * @param extras
	 * @return
	 */
	public PushRequest addExtras(Map<String, String> extras) {
		this.extras.putAll(extras);
		return this;
	}

	/**
	 * 添加扩展类型和数据
	 *
	 * @param type
	 * @param data
	 * @return
	 */
	public PushRequest addExtra(ValueEnum<String> type, Object data) {
		addExtra("type", type.value());
		addExtra("data", JsonKit.INSTANCE.toJson(data));
		return this;
	}

	public Map<String, String> getExtras() {
		return this.extras;
	}

	public String getMessage() {
		return message;
	}

	public PushRequest setMessage(String message) {
		this.message = message;
		return this;
	}
}
